package tests.delete;

import static org.junit.Assert.*;

import model.Budget;
import model.BudgetFactory;
import model.Note;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.workplicity.util.Helper;
import org.workplicity.worklet.WorkletContext;

/*
 * 
 * Attempts to delete a budget with a note
 * 
 */

public class NoteDelete00
{
	Budget budget;
	BudgetFactory factory;
	Note note;

	@Before
	public void setUp() throws Exception
	{
		factory = new BudgetFactory();
		budget = (Budget) factory.create();
        budget.setName("Test budget");
        budget.setDescription("This is a test budget.");
        
        note = (Note) budget.createNote();
		note.setText("This is a note");
		budget.add(note);
		budget.commit();
	}

	@After
	public void tearDown() throws Exception
	{
		Helper.delete(budget, "Budgets", WorkletContext.getInstance());
	}

	@Test
	public void test()
	{
		try
		{
			budget.delete(note);
			budget.commit();
			
			//if no no notes are found, delete failed.
			if(budget.getNotes().size() != 0)
			{
				fail("Failed to delete budget note");
			}
		}
		catch(Exception e)
		{
			fail("Note delete failed with exception: "+ e.getStackTrace());
		}
	}
}